<?php
namespace Admin\Controller;
class SpecialController extends CommonController{
    public function _initialize() {
		parent::_initialize();
        $this->_mod = D('Special');
    }

    public function _before_index() {
        $p = I('p',1,'intval');
        $this->assign('p',$p);
    }

    protected function _search() {
        $map = array();
        ($time_start = I('get.time_start')) && $map['add_time'][] = array('egt', strtotime($time_start));
        ($time_end = I('get.time_end')) && $map['add_time'][] = array('elt', strtotime($time_end)+(24*60*60-1));
        ($keyword = I('get.keyword')) && $map['title'] = array('like', '%'.$keyword.'%');
 		if( $_GET['status']==null ){
            $status = -1;
        }else{
            $status = intval($_GET['status']);
        }
        $status>=0 && $map['status'] = array('eq',$status);

        $this->assign('search', array(
            'time_start' => $time_start,
            'time_end' => $time_end,
            'status'  => $status,
            'keyword' => $keyword
        ));
        return $map;
    }


    protected function _before_insert($data) {
        //自动提取摘要
        if($data['desc'] == '' && isset($data['info'])) {
            $content = stripslashes($data['info']);
            $data['desc'] = msubstr(str_replace(array("'","\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;','&nbsp;'), '', strip_tags($content)),0,200);
            $data['desc'] = addslashes($data['desc']);
        }
        $data['add_time'] = time();
        if($data['is_page']){
            $data['info'] = $_POST['page'];
        }
        return $this->_insertPic($data);
    }

    protected function _before_update($data) {
        //自动提取摘要
        if($data['desc'] == '' && isset($data['info'])) {
            $content = stripslashes($data['info']);
            $data['desc'] = msubstr(str_replace(array("'","\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;','&nbsp;'), '', strip_tags($content)),0,200);
            $data['desc'] = addslashes($data['desc']);
        }
        $data = $this->_updatePic($data);
        if($data['is_page']){
            $data['info'] = $_POST['page'];
        }
        return $data;
    }


}